package com.gxa.p2p.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.BankCard4EVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.BankCard4EVerificationResponse;
import com.tencentcloudapi.faceid.v20180301.models.IdCardOCRVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.IdCardOCRVerificationResponse;

/**
 * 疼讯 认证接口
 */
public class Authentic{
        static  FaceidClient client;
        static {   //设置密钥
                Credential cred = new Credential("AKIDzBCsJSKDgtDF0Yo70jX8UZOO6XhiMxL7", "fT0GFxNVMxOaZbyKm2A3g1UknZ3NWRyF");

                HttpProfile httpProfile = new HttpProfile();
                httpProfile.setEndpoint("faceid.tencentcloudapi.com");

                ClientProfile clientProfile = new ClientProfile();
                clientProfile.setHttpProfile(httpProfile);

                client = new FaceidClient(cred, "ap-chengdu", clientProfile);
        }

        /**
         * 查询身份证对应信息
         * @param idCard 身份证号
         * @param name  姓名
         * @return
         * @throws TencentCloudSDKException
         */
    public static JSONObject authenticIDCard(String idCard, String name) throws TencentCloudSDKException {

            String params = "{\"IdCard\":\""+idCard+"\",\"Name\":\""+name+"\"}";
            IdCardOCRVerificationRequest req = IdCardOCRVerificationRequest.fromJsonString(params, IdCardOCRVerificationRequest.class);

            IdCardOCRVerificationResponse resp = client.IdCardOCRVerification(req);

            return JSON.parseObject(IdCardOCRVerificationResponse.toJsonString(resp));

    }

        /**
         * 查询用户银行卡与用户关联关系
         * @param name 开户姓名
         * @param bankCard 卡号
         * @param phone 预留手机号
         * @param IdCard 身份证号
         * @return
         * @throws TencentCloudSDKException
         */
    public static JSONObject authrenBankCard(String name, String bankCard, String phone, String IdCard) throws TencentCloudSDKException {
        System.out.println("phone: "+phone);
            String params = "{\"Name\":\""+name+"\",\"BankCard\":\""+bankCard+"\",\"Phone\":\""+phone+"\",\"IdCard\":\""+IdCard+"\"}";
            BankCard4EVerificationRequest req = BankCard4EVerificationRequest.fromJsonString(params, BankCard4EVerificationRequest.class);

            BankCard4EVerificationResponse resp = client.BankCard4EVerification(req);
            // 返回一个Json对象
            return JSON.parseObject(BankCard4EVerificationResponse.toJsonString(resp));

    }
}
